<template>
  <el-container class="main-layout" :class="{ 'light-theme': isLightTheme }">
    <!-- 侧边栏 -->
    <el-aside :width="sidebarCollapsed ? '64px' : '240px'" class="sidebar">
      <div class="sidebar-header">
        <div class="logo">
          <div v-if="!sidebarCollapsed" class="logo-icon">
            <img src="https://images.weserv.nl/?url=gitee.com%2Fshen-yulin20051127%2Fimage-storage%2Fraw%2Fmaster%2Favatars%2Fefa3957d-5f75-4176-af53-dc505ed9facb.png" style="width:32px;height:32px;object-fit:contain;" />
          </div>
          <span v-if="!sidebarCollapsed" class="logo-text">SG3L</span>
          <div v-else class="logo-collapsed">S</div>
        </div>
      </div>

      <el-menu :default-active="$route.path" class="sidebar-menu" :collapse="sidebarCollapsed"
        :collapse-transition="false" router>
        <!-- 动态渲染菜单 -->
        <template v-for="(group, groupIndex) in groupedMenus" :key="groupIndex">
          <!-- 菜单分组标题 -->
          <div class="menu-group" v-if="!sidebarCollapsed && group.title">
            <span class="menu-group-title">{{ group.title }}</span>
          </div>

          <!-- 渲染分组下的菜单项 -->
          <template v-for="menu in group.menus" :key="menu.id">
            <!-- 有子菜单的情况 -->
            <template v-if="menu.children && menu.children.length > 0">
              <el-sub-menu :index="menu.menuCode">
                <template #title>
                  <el-icon>
                    <component :is="getIconComponent(menu.icon)" />
                  </el-icon>
                  <span>{{ menu.menuName }}</span>
                </template>
                <el-menu-item v-for="child in menu.children" :key="child.id" :index="child.path">
                  <el-icon>
                    <component :is="getIconComponent(child.icon)" />
                  </el-icon>
                  <span>{{ child.menuName }}</span>
                </el-menu-item>
              </el-sub-menu>
            </template>

            <!-- 没有子菜单的情况 -->
            <template v-else>
              <el-menu-item :index="menu.path">
                <el-icon>
                  <component :is="getIconComponent(menu.icon)" />
                </el-icon>
                <span>{{ menu.menuName }}</span>
              </el-menu-item>
            </template>
          </template>
        </template>
      </el-menu>
    </el-aside>

    <!-- 主内容区 -->
    <el-container class="main-container">
      <!-- 顶部导航 -->
      <el-header class="header">
        <div class="header-left">
          <el-button :icon="Fold" circle @click="toggleSidebar" class="collapse-btn" />
          <el-breadcrumb separator="/" class="breadcrumb">
            <el-breadcrumb-item to="/">首页</el-breadcrumb-item>
            <el-breadcrumb-item v-if="$route.meta.title">
              {{ $route.meta.title }}
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>

        <div class="header-right">
          <el-tooltip content="切换主题" placement="bottom">
            <el-button circle @click="toggleTheme">
              <el-icon>
                <Sunny />
              </el-icon>
            </el-button>
          </el-tooltip>

          <!-- 用户信息 -->
          <el-dropdown @command="handleUserCommand">
            <div class="user-info">
              <el-avatar :size="32" :src="processAvatarUrl(userStore.avatar)">
                <template v-if="!userStore.avatar">
                  {{ userStore.username?.charAt(0)?.toUpperCase() || 'U' }}
                </template>
              </el-avatar>
              <span class="username">{{ userStore.username || '用户' }}</span>
              <el-icon class="dropdown-icon">
                <ArrowDown />
              </el-icon>
            </div>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="profile">
                  <el-icon>
                    <User />
                  </el-icon> 个人资料
                </el-dropdown-item>
                <el-dropdown-item divided command="logout">
                  <el-icon style="color: #f56c6c">
                    <SwitchButton />
                  </el-icon> 退出登录
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>

      <!-- 页面内容 -->
      <el-main class="main-content">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </el-main>
    </el-container>
  </el-container>

  <!-- 消息通知弹窗 -->
  <el-dialog v-model="showNotificationDialog" title="消息通知" width="400px" :destroy-on-close="false"
    class="notification-dialog">
    <div class="notification-list">
      <div v-for="item in notifications" :key="item.id" class="notification-item" :class="{ read: item.read }"
        @click="markAsRead(item.id)">
        <div class="notification-content">
          <div class="notification-title">{{ item.title }}</div>
          <div class="notification-time">{{ item.time }}</div>
        </div>
      </div>
    </div>
  </el-dialog>
</template>

<script setup>
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
// 头像URL处理函数 - 解决Gitee/OSS等外链CORS问题，与UserProfile.vue保持一致
const processAvatarUrl = (url) => {
  if (!url) return url
  // 只要是http开头的都走代理，兼容gitee、oss等
  if (url.startsWith('http')) {
    return `https://images.weserv.nl/?url=${encodeURIComponent(url.replace(/^https?:\/\//, ''))}`
  }
  return url
}
import {
  Odometer,
  TrendCharts,
  Monitor,
  Grid,
  Histogram,
  User,
  UserFilled,
  Document,
  Fold,
  Search,
  Sunny,
  Bell,
  ArrowDown,
  Setting,
  SwitchButton,
  Collection,
  Plus,
  Star,
  Clock,
  Close,
  Delete,
  Files,
  Key,
  Link,
  Management,
  DataAnalysis,
  CircleCheck,
  Warning,
  CircleClose,
  Menu
} from '@element-plus/icons-vue'

// 响应式数据
const sidebarCollapsed = ref(false)
const searchText = ref('')
const unreadCount = ref(5)
const isLightTheme = ref(false) // 主题切换状态
const showSearchHistory = ref(false)
const showNotificationDialog = ref(false) // 修复未定义警告
const searchHistory = ref([])
const notifications = ref([])
const notificationSimulationEnabled = ref(true) // 控制是否启用实时通知模拟
const notificationTimer = ref(null) // 通知定时器

// Store 和 Router
const userStore = useUserStore()
const router = useRouter()

// 动态菜单数据
const dynamicMenus = computed(() => {
  return userStore.formattedMenus || {}
})

// 分组菜单数据
const groupedMenus = computed(() => {
  const menuGroups = dynamicMenus.value
  const result = []

  // 按照分组顺序添加菜单
  const groupOrder = ['工作台', '开发工具', '系统管理']

  groupOrder.forEach(groupTitle => {
    if (menuGroups[groupTitle] && menuGroups[groupTitle].length > 0) {
      result.push({
        title: groupTitle,
        menus: menuGroups[groupTitle]
      })
    }
  })

  return result
})

// 图标组件映射
const iconComponentMap = {
  // 系统图标
  'Dashboard': Odometer,
  'Odometer': Odometer,
  'TrendCharts': TrendCharts,
  'BarChart': TrendCharts,
  'Monitor': Monitor,
  'Grid': Grid,
  'Histogram': Histogram,
  'User': User,
  'UserFilled': UserFilled,
  'UserGroup': UserFilled,
  'Document': Document,
  'Setting': Setting,
  'Key': Key,
  'Lock': Key,
  'Menu': Management,
  'Management': Management,
  'Collection': Collection,
  'Plus': Plus,
  'Star': Star,
  'Clock': Clock,
  'Files': Files,
  'Link': Link,
  'DataAnalysis': DataAnalysis,
  'Bell': Bell,
  // 默认图标
  'default': Menu
}

// 获取图标组件
const getIconComponent = (iconName) => {
  return iconComponentMap[iconName] || iconComponentMap['default']
}

// 模拟消息数据
const mockNotifications = [
  {
    id: 1,
    type: 'info',
    title: '系统更新',
    message: '系统将于今晚23:00进行版本更新，预计用时30分钟',
    time: new Date(Date.now() - 2 * 60 * 60 * 1000), // 2小时前
    read: false,
    action: null
  },
  {
    id: 2,
    type: 'success',
    title: '数据备份完成',
    message: '系统数据备份已成功完成，备份文件已保存至云端',
    time: new Date(Date.now() - 4 * 60 * 60 * 1000), // 4小时前
    read: false,
    action: 'view-backup'
  },
  {
    id: 3,
    type: 'warning',
    title: '用户权限变更',
    message: '管理员张三的权限已被修改，请及时查看权限变更记录',
    time: new Date(Date.now() - 6 * 60 * 60 * 1000), // 6小时前
    read: false,
    action: 'view-permissions'
  },
  {
    id: 4,
    type: 'error',
    title: '登录异常',
    message: '检测到异常IP地址尝试登录管理员账户，已自动拦截',
    time: new Date(Date.now() - 8 * 60 * 60 * 1000), // 8小时前
    read: true,
    action: 'view-security'
  },
  {
    id: 5,
    type: 'info',
    title: '新用户注册',
    message: '用户"李四"已完成注册，等待管理员审核',
    time: new Date(Date.now() - 12 * 60 * 60 * 1000), // 12小时前
    read: true,
    action: 'view-users'
  }
]

// 初始化通知数据
const initNotifications = () => {
  notifications.value = [...mockNotifications]
  updateUnreadCount()
}

// 更新未读数量
const updateUnreadCount = () => {
  unreadCount.value = notifications.value.filter(n => !n.read).length
}

// 搜索数据源
const searchData = [
  // 菜单项
  { title: '仪表盘', description: '查看系统总览数据', type: '菜单', path: '/home', icon: 'Odometer', typeClass: 'menu-icon' },
  { title: '分析页', description: '数据分析和统计', type: '菜单', path: '/home/analytics', icon: 'TrendCharts', typeClass: 'menu-icon' },
  { title: '监控页', description: '系统监控和状态', type: '菜单', path: '/home/monitoring', icon: 'Monitor', typeClass: 'menu-icon' },
  { title: '模板案例', description: '查看所有模板', type: '菜单', path: '/home/template-center/templates', icon: 'Collection', typeClass: 'menu-icon' },
  { title: '创建模板', description: '创建新的模板', type: '菜单', path: '/home/template-center/create', icon: 'Plus', typeClass: 'menu-icon' },
  { title: '基本组件', description: 'UI基础组件库', type: '菜单', path: '/home/component-center/basic', icon: 'Grid', typeClass: 'menu-icon' },
  { title: '图标组件', description: '图标组件展示', type: '菜单', path: '/home/component-center/icons', icon: 'Star', typeClass: 'menu-icon' },
  { title: '图形组件', description: '图表组件展示', type: '菜单', path: '/home/component-center/charts', icon: 'TrendCharts', typeClass: 'menu-icon' },
  { title: '用户管理', description: '管理系统用户', type: '菜单', path: '/home/users', icon: 'User', typeClass: 'menu-icon' },
  { title: '角色管理', description: '管理用户角色', type: '菜单', path: '/home/roles', icon: 'UserFilled', typeClass: 'menu-icon' },
  { title: '权限管理', description: '管理系统权限', type: '菜单', path: '/home/permissions', icon: 'Key', typeClass: 'menu-icon' },
  { title: '系统设置', description: '系统配置和设置', type: '菜单', path: '/home/settings', icon: 'Setting', typeClass: 'menu-icon' },
  { title: '日志中心', description: '查看系统日志', type: '菜单', path: '/home/logs', icon: 'Document', typeClass: 'menu-icon' },

  // 功能项
  { title: '添加用户', description: '创建新用户账户', type: '功能', action: 'add-user', icon: 'Plus', typeClass: 'action-icon' },
  { title: '导入用户', description: '批量导入用户数据', type: '功能', action: 'import-users', icon: 'Files', typeClass: 'action-icon' },
  { title: '角色分配', description: '为用户分配角色', type: '功能', action: 'assign-role', icon: 'Management', typeClass: 'action-icon' },
  { title: '数据分析', description: '查看数据分析报告', type: '功能', action: 'data-analysis', icon: 'DataAnalysis', typeClass: 'action-icon' },
  { title: '系统备份', description: '备份系统数据', type: '功能', action: 'system-backup', icon: 'Files', typeClass: 'action-icon' },

  // 快捷链接
  { title: '官方文档', description: '查看系统使用文档', type: '链接', url: 'https://docs.example.com', icon: 'Link', typeClass: 'link-icon' },
  { title: '技术支持', description: '获取技术支持帮助', type: '链接', url: 'https://support.example.com', icon: 'Link', typeClass: 'link-icon' }
]

// 初始化搜索历史
onMounted(() => {
  const saved = localStorage.getItem('globalSearchHistory')
  if (saved) {
    searchHistory.value = JSON.parse(saved)
  }

  // 初始化通知
  initNotifications()

  // 添加快捷键监听
  document.addEventListener('keydown', handleKeydown)

  // 模拟实时消息推送
  // startNotificationSimulation()
})

// 清理事件监听
onUnmounted(() => {
  document.removeEventListener('keydown', handleKeydown)
  if (notificationTimer.value) {
    clearInterval(notificationTimer.value)
  }
})

// // 模拟消息推送
// const startNotificationSimulation = () => {
//   if (!notificationSimulationEnabled.value) return

//   // 每15秒随机推送一条消息（仅用于演示）
//   notificationTimer.value = setInterval(() => {
//     if (notificationSimulationEnabled.value) {
//       addRandomNotification()
//     }
//   }, 15000)
// }

// // 添加随机通知
// const addRandomNotification = () => {
//   // const randomIndex = Math.floor(Math.random() * simulateNotifications.length)
//   // const notificationTemplate = simulateNotifications[randomIndex]

//   const newNotification = {
//     id: Date.now(),
//     // type: notificationTemplate.type,
//     // title: notificationTemplate.title,
//     // message: notificationTemplate.message,
//     time: new Date(), // 保持为 Date 对象
//     read: false,
//     action: getRandomAction()
//   }

//   // 添加到列表顶部
//   notifications.value.unshift(newNotification)
//   updateUnreadCount()

//   // 显示浮动提示
//   showFloatingNotification(newNotification)

//   // 限制通知数量
//   if (notifications.value.length > 50) {
//     notifications.value = notifications.value.slice(0, 50)
//   }
// }

// 获取随机动作
const getRandomAction = () => {
  const actions = [
    'view-backup', 'view-permissions', 'view-security',
    'view-users', 'view-tasks', 'view-monitoring'
  ]
  return Math.random() > 0.5 ? actions[Math.floor(Math.random() * actions.length)] : null
}

// 显示浮动通知提示
const showFloatingNotification = (notification) => {
  ElNotification({
    title: notification.title,
    message: notification.message,
    type: notification.type === 'error' ? 'error' : notification.type === 'success' ? 'success' : notification.type === 'warning' ? 'warning' : 'info',
    duration: 4000,
    position: 'top-right'
  })
}

// 切换侧边栏
const toggleSidebar = () => {
  sidebarCollapsed.value = !sidebarCollapsed.value
}

// 切换主题
const toggleTheme = () => {
  isLightTheme.value = !isLightTheme.value
  localStorage.setItem('theme', isLightTheme.value ? 'light' : 'dark')
  ElMessage.success(`已切换到${isLightTheme.value ? '浅色' : '深色'}主题`)
}

// 初始化主题
const initTheme = () => {
  const savedTheme = localStorage.getItem('theme')
  if (savedTheme) {
    isLightTheme.value = savedTheme === 'light'
  }
}
initTheme()

// 处理用户下拉菜单命令
const handleUserCommand = (command) => {
  switch (command) {
    case 'profile':
      router.push('/home/profile')
      break
    case 'logout':
      ElMessageBox.confirm('确定要退出登录吗？', '确认退出', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          userStore.logout()
          router.push('/login')
          ElMessage.success('已成功退出登录')
        })
        .catch(() => {
          ElMessage.info('已取消退出')
        })
      break
  }
}

// 标记消息为已读
const markAsRead = (id) => {
  const msg = notifications.value.find(n => n.id === id)
  if (msg && !msg.read) {
    msg.read = true
    ElMessage.success('消息已读')
  }
}

// 消息通知相关功能
const handleNotificationCommand = (command) => {
  console.log('Notification command:', command)
}

// 获取通知图标
const getNotificationIcon = (type) => {
  const iconMap = {
    info: 'Bell',
    success: 'CircleCheck',
    warning: 'Warning',
    error: 'CircleClose'
  }
  return iconMap[type] || 'Bell'
}

// 格式化时间
const formatTime = (time) => {
  // 确保 time 是 Date 对象
  const timeObj = time instanceof Date ? time : new Date(time)

  // 检查是否是有效的日期
  if (isNaN(timeObj.getTime())) {
    return '时间无效'
  }

  const now = new Date()
  const diff = now - timeObj
  const minutes = Math.floor(diff / (1000 * 60))
  const hours = Math.floor(diff / (1000 * 60 * 60))
  const days = Math.floor(diff / (1000 * 60 * 60 * 24))

  if (minutes < 1) return '刚刚'
  if (minutes < 60) return `${minutes}分钟前`
  if (hours < 24) return `${hours}小时前`
  if (days < 7) return `${days}天前`

  return timeObj.toLocaleDateString()
}

// 处理通知点击
const handleNotificationClick = (notification, index) => {
  // 标记为已读
  if (!notification.read) {
    notification.read = true
    updateUnreadCount()
  }

  // 执行相应动作
  if (notification.action) {
    handleNotificationAction(notification.action)
  }
}

// 处理通知动作
const handleNotificationAction = (action) => {
  const actionMap = {
    'view-backup': () => {
      router.push('/home/settings')
      ElMessage.info('跳转到系统设置查看备份')
    },
    'view-permissions': () => {
      router.push('/home/permissions')
      ElMessage.info('跳转到权限管理')
    },
    'view-security': () => {
      router.push('/home/logs')
      ElMessage.info('跳转到日志中心查看安全记录')
    },
    'view-users': () => {
      router.push('/home/users')
      ElMessage.info('跳转到用户管理')
    },
    'view-tasks': () => {
      ElMessage.info('任务管理功能开发中...')
    },
    'view-monitoring': () => {
      router.push('/home/monitoring')
      ElMessage.info('跳转到监控页面')
    }
  }

  const handler = actionMap[action]
  if (handler) {
    handler()
  }
}
function handleKeydown(event) {
  // TODO: 根据需要补充快捷键处理逻辑
}
</script>

<style scoped lang="scss">
.main-layout {
  height: 100vh;

  .sidebar {
    background: linear-gradient(180deg, #1e293b 0%, #334155 100%);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    transition: width 0.3s ease;

    .sidebar-header {
      height: 64px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-bottom: 1px solid rgba(255, 255, 255, 0.1);

      .logo {
        display: flex;
        align-items: center;
        color: white;

        .logo-icon {
          width: 32px;
          height: 32px;
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
          border-radius: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 16px;
          font-weight: 600;
          color: white;
          margin-right: 12px;
        }

        .logo-text {
          font-size: 18px;
          font-weight: 600;
        }

        .logo-collapsed {
          width: 32px;
          height: 32px;
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
          border-radius: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 16px;
          font-weight: 600;
          color: white;
        }
      }
    }

    .menu-group {
      padding: 16px 20px 8px;

      .menu-group-title {
        font-size: 12px;
        color: rgba(255, 255, 255, 0.6);
        text-transform: uppercase;
        letter-spacing: 1px;
      }
    }

    .sidebar-menu {
      background: transparent;
      border: none;

      :deep(.el-menu-item) {
        color: rgba(255, 255, 255, 0.8);
        margin: 4px 12px;
        border-radius: 8px;
        height: 44px;
        line-height: 44px;
        outline: none !important;
        user-select: none;
        -webkit-tap-highlight-color: transparent;

        &:hover {
          background: rgba(255, 255, 255, 0.1);
          color: white;
        }

        &:focus {
          outline: none !important;
          box-shadow: none !important;
        }

        &:active {
          outline: none !important;
          box-shadow: none !important;
        }

        &.is-active {
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
          color: white;
        }

        .el-icon {
          margin-right: 12px;
          font-size: 16px;
        }

        span {
          user-select: none;
          outline: none !important;
        }
      }

      :deep(.el-sub-menu) {
        .el-sub-menu__title {
          color: rgba(255, 255, 255, 0.8);
          margin: 4px 12px;
          border-radius: 8px;
          height: 44px;
          line-height: 44px;
          outline: none !important;
          user-select: none;
          -webkit-tap-highlight-color: transparent;

          &:hover {
            background: rgba(255, 255, 255, 0.1);
            color: white;
          }

          &:focus {
            outline: none !important;
            box-shadow: none !important;
          }

          &:active {
            outline: none !important;
            box-shadow: none !important;
          }

          .el-icon {
            margin-right: 12px;
            font-size: 16px;
          }

          span {
            user-select: none;
            outline: none !important;
          }
        }

        .el-menu {
          background: rgba(0, 0, 0, 0.1);

          .el-menu-item {
            color: rgba(255, 255, 255, 0.7);
            margin: 2px 8px;
            padding-left: 40px !important;
            outline: none !important;
            user-select: none;
            -webkit-tap-highlight-color: transparent;

            &:hover {
              background: rgba(255, 255, 255, 0.1);
              color: white;
            }

            &:focus {
              outline: none !important;
              box-shadow: none !important;
            }

            &:active {
              outline: none !important;
              box-shadow: none !important;
            }

            &.is-active {
              background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
              color: white;
            }

            span {
              user-select: none;
              outline: none !important;
            }
          }
        }

        &.is-opened>.el-sub-menu__title {
          color: white;
        }
      }

      &.el-menu--collapse {
        :deep(.el-menu-item) {
          padding: 0 20px;

          .el-icon {
            margin-right: 0;
          }
        }

        :deep(.el-sub-menu) {
          .el-sub-menu__title {
            padding: 0 20px;

            .el-icon {
              margin-right: 0;
            }
          }
        }
      }
    }
  }

  .main-container {
    flex: 1;

    .header {
      background: white;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 24px;
      height: 64px;

      .header-left {
        display: flex;
        align-items: center;
        gap: 16px;

        .collapse-btn {
          color: #606266;
        }

        .breadcrumb {
          :deep(.el-breadcrumb__inner) {
            color: #606266;

            &.is-link {
              color: #409eff;

              &:hover {
                color: #66b1ff;
              }
            }
          }
        }
      }

      .header-right {
        display: flex;
        align-items: center;
        gap: 16px;

        .global-search {
          position: relative;

          .search-input {
            width: 280px;
            transition: width 0.3s ease;

            &:focus-within {
              width: 320px;
            }

            :deep(.el-input__inner) {
              border-radius: 20px;
              border: 1px solid #e4e7ed;
              background: #f8f9fa;
              transition: all 0.3s ease;

              &:focus {
                border-color: #409eff;
                background: white;
                box-shadow: 0 2px 8px rgba(64, 158, 255, 0.2);
              }
            }

            :deep(.el-input__suffix) {
              .search-shortcut {
                font-size: 11px;
                color: #909399;
                background: #f0f0f0;
                padding: 2px 6px;
                border-radius: 4px;
                margin-right: 8px;
                font-family: monospace;
              }
            }
          }

          .search-history-dropdown {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            background: white;
            border: 1px solid #e4e7ed;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            z-index: 2000;
            margin-top: 4px;

            .history-header {
              display: flex;
              justify-content: space-between;
              align-items: center;
              padding: 12px 16px;
              border-bottom: 1px solid #f0f0f0;
              font-size: 12px;
              color: #909399;
              font-weight: 500;
            }

            .history-items {
              max-height: 200px;
              overflow-y: auto;

              .history-item {
                display: flex;
                align-items: center;
                padding: 8px 16px;
                cursor: pointer;
                transition: background-color 0.2s ease;

                &:hover {
                  background: #f5f7fa;
                }

                .el-icon {
                  color: #909399;
                  margin-right: 8px;
                  font-size: 14px;
                }

                span {
                  flex: 1;
                  font-size: 13px;
                  color: #606266;
                }

                .el-button {
                  opacity: 0;
                  transition: opacity 0.2s ease;
                }

                &:hover .el-button {
                  opacity: 1;
                }
              }
            }
          }
        }

        .notification-dropdown {
          .notification-badge {
            :deep(.el-badge__content) {
              background: #f56c6c;
              border: 2px solid white;
            }
          }
        }

        .user-info {
          display: flex;
          align-items: center;
          gap: 8px;
          cursor: pointer;
          padding: 8px 12px;
          border-radius: 8px;
          transition: background-color 0.3s ease;

          &:hover {
            background: #f0f2f5;
          }

          .username {
            font-size: 14px;
            color: #606266;
            font-weight: 500;
          }

          .dropdown-icon {
            font-size: 12px;
            color: #909399;
          }
        }
      }
    }

    .main-content {
      background: #f5f7fa;
      padding: 0;
      overflow: auto;

      .fade-enter-active,
      .fade-leave-active {
        transition: opacity 0.3s ease;
      }

      .fade-enter-from,
      .fade-leave-to {
        opacity: 0;
      }
    }
  }
}

// 浅色主题样式 - 仅修改颜色，不改变布局和尺寸
.main-layout.light-theme {
  .sidebar {
    background: linear-gradient(180deg, #f0f2f5 0%, #e5e6eb 100%);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);

    .sidebar-header {
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);

      .logo {
        color: #1e293b;

        .logo-icon,
        .logo-collapsed {
          background: linear-gradient(135deg, #409eff 0%, #6aa8ff 100%);
        }
      }
    }

    .menu-group-title {
      color: rgba(0, 0, 0, 0.6);
    }

    .sidebar-menu {
      :deep(.el-menu-item) {
        color: rgba(0, 0, 0, 0.7);

        &:hover {
          background: rgba(0, 0, 0, 0.05);
          color: #1e293b;
        }

        &.is-active {
          background: linear-gradient(135deg, #409eff 0%, #6aa8ff 100%);
        }
      }

      :deep(.el-sub-menu) {
        .el-sub-menu__title {
          color: rgba(0, 0, 0, 0.7);

          &:hover {
            background: rgba(0, 0, 0, 0.05);
            color: #1e293b;
          }
        }

        .el-menu {
          background: rgba(0, 0, 0, 0.03);

          .el-menu-item {
            color: rgba(0, 0, 0, 0.6);

            &:hover {
              background: rgba(0, 0, 0, 0.05);
              color: #1e293b;
            }
          }
        }

        &.is-opened>.el-sub-menu__title {
          color: #1e293b;
        }
      }
    }
  }

  .main-container {
    .header {
      background: #f8fafc;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .main-content {
      background: #ffffff;
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .main-layout {
    .sidebar {
      width: 64px !important;

      .menu-group {
        display: none;
      }
    }

    .header {
      padding: 0 16px;

      .header-left {
        .breadcrumb {
          display: none;
        }
      }

      .header-right {
        gap: 8px;

        .search-input {
          width: 120px;
        }

        .user-info {
          .username {
            display: none;
          }
        }
      }
    }
  }
}

/* 全局移除焦点和选中效果 */
* {
  -webkit-tap-highlight-color: transparent !important;
  outline: none !important;
}

*:focus {
  outline: none !important;
  box-shadow: none !important;
}

*:active {
  outline: none !important;
}

.sidebar * {
  user-select: none !important;
}

/* 布局高度 */
.main-layout {
  height: 100vh;
}

/* 侧边栏 */
.sidebar {
  background: linear-gradient(180deg, #1e293b 0%, #334155 100%);
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  transition: width 0.3s ease;
}

.sidebar-header {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
  display: flex;
  align-items: center;
  color: white;
}

.logo-icon,
.logo-collapsed {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: white;
}

.logo-icon {
  margin-right: 12px;
}

.menu-group {
  padding: 16px 20px 8px;
}

.menu-group-title {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-menu {
  background: transparent;
  border: none;
}

.sidebar-menu :deep(.el-menu-item) {
  color: rgba(255, 255, 255, 0.8);
  margin: 4px 12px;
  border-radius: 8px;
  height: 44px;
  line-height: 44px;
  outline: none !important;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-menu :deep(.el-menu-item:hover) {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.sidebar-menu :deep(.el-menu-item.is-active) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.sidebar-menu :deep(.el-menu-item .el-icon) {
  margin-right: 12px;
  font-size: 16px;
}

.sidebar-menu :deep(.el-sub-menu__title) {
  color: rgba(255, 255, 255, 0.8);
  margin: 4px 12px;
  border-radius: 8px;
  height: 44px;
  line-height: 44px;
  outline: none !important;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-menu :deep(.el-sub-menu__title:hover) {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.sidebar-menu :deep(.el-sub-menu.is-opened > .el-sub-menu__title) {
  color: white;
}

.sidebar-menu :deep(.el-sub-menu__title .el-icon) {
  margin-right: 12px;
  font-size: 16px;
}

.sidebar-menu :deep(.el-sub-menu .el-menu) {
  background: rgba(0, 0, 0, 0.1);
}

.sidebar-menu :deep(.el-sub-menu .el-menu-item) {
  color: rgba(255, 255, 255, 0.7);
  margin: 2px 8px;
  padding-left: 40px !important;
}

.sidebar-menu :deep(.el-sub-menu .el-menu-item:hover) {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.sidebar-menu :deep(.el-sub-menu .el-menu-item.is-active) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

/* 主容器 */
.main-container {
  flex: 1;
}

.header {
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 64px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.collapse-btn {
  color: #606266;
}

.breadcrumb :deep(.el-breadcrumb__inner) {
  color: #606266;
}

.breadcrumb :deep(.el-breadcrumb__inner.is-link) {
  color: #409eff;
}

.breadcrumb :deep(.el-breadcrumb__inner.is-link:hover) {
  color: #66b1ff;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.search-input {
  width: 200px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background-color 0.3s ease;
}

.user-info:hover {
  background: #f0f2f5;
}

.username {
  font-size: 14px;
  color: #606266;
  font-weight: 500;
}

.dropdown-icon {
  font-size: 12px;
  color: #909399;
}

.main-content {
  background: #f5f7fa;
  padding: 0;
  overflow: auto;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 浅色主题 */
.main-layout.light-theme .sidebar {
  background: linear-gradient(180deg, #f0f2f5 0%, #e5e6eb 100%);
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
}

.main-layout.light-theme .sidebar-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.main-layout.light-theme .logo {
  color: #1e293b;
}

.main-layout.light-theme .logo-icon,
.main-layout.light-theme .logo-collapsed {
  background: linear-gradient(135deg, #409eff 0%, #6aa8ff 100%);
}

.main-layout.light-theme .menu-group-title {
  color: rgba(0, 0, 0, 0.6);
}

.main-layout.light-theme .sidebar-menu :deep(.el-menu-item),
.main-layout.light-theme .sidebar-menu :deep(.el-sub-menu__title) {
  color: rgba(0, 0, 0, 0.7);
}

.main-layout.light-theme .sidebar-menu :deep(.el-menu-item:hover),
.main-layout.light-theme .sidebar-menu :deep(.el-sub-menu__title:hover) {
  background: rgba(0, 0, 0, 0.05);
  color: #1e293b;
}

.main-layout.light-theme .sidebar-menu :deep(.el-menu-item.is-active),
.main-layout.light-theme .sidebar-menu :deep(.el-sub-menu.is-opened > .el-sub-menu__title) {
  color: #1e293b;
}

.main-layout.light-theme .main-container .header {
  background: #f8fafc;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.main-layout.light-theme .main-content {
  background: #ffffff;
}

/* 响应式 */
@media (max-width: 768px) {
  .main-layout .sidebar {
    width: 64px !important;
  }

  .main-layout .sidebar .menu-group {
    display: none;
  }

  .main-layout .header {
    padding: 0 16px;
  }

  .main-layout .header-left .breadcrumb {
    display: none;
  }

  .main-layout .header-right {
    gap: 8px;
  }

  .main-layout .header-right .search-input {
    width: 120px;
  }

  .main-layout .header-right .user-info .username {
    display: none;
  }
}

// 消息通知下拉菜单样式
:deep(.notification-menu) {
  width: 380px !important;
  max-height: 520px;
  padding: 0;
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.05);
  overflow: hidden;

  .notification-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;

    .notification-title {
      display: flex;
      align-items: center;
      gap: 12px;
      font-size: 18px;
      font-weight: 600;

      .el-icon {
        font-size: 20px;
        color: white;
      }

      .el-tag {
        background: rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(255, 255, 255, 0.3);
        color: white;
        font-weight: 500;
        backdrop-filter: blur(10px);
      }
    }

    .notification-actions {
      display: flex;
      gap: 12px;

      .el-button {
        padding: 8px 16px;
        font-size: 13px;
        color: white;
        background: rgba(255, 255, 255, 0.15);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 8px;
        backdrop-filter: blur(10px);
        transition: all 0.3s ease;

        &:hover {
          background: rgba(255, 255, 255, 0.25);
          transform: translateY(-1px);
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        }
      }
    }
  }

  .notification-list {
    max-height: 360px;
    overflow-y: auto;
    padding: 8px 0;

    /* 自定义滚动条 */
    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: #f1f1f1;
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb:hover {
      background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    }

    .empty-notifications {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 60px 20px;
      color: #909399;

      .el-icon {
        font-size: 64px;
        margin-bottom: 16px;
        opacity: 0.3;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
      }

      span {
        font-size: 16px;
        font-weight: 500;
      }
    }

    .notification-item {
      display: flex;
      align-items: flex-start;
      padding: 16px 24px;
      margin: 4px 12px;
      border-radius: 12px;
      cursor: pointer;
      transition: all 0.3s ease;
      position: relative;
      border: 1px solid transparent;

      &:hover {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
        border-color: rgba(102, 126, 234, 0.2);
        transform: translateY(-2px);
        box-shadow: 0 4px 16px rgba(102, 126, 234, 0.1);
      }

      &.unread {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
        border-left: 4px solid;
        border-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%) 1;

        &::before {
          content: '';
          position: absolute;
          left: 0;
          top: 0;
          bottom: 0;
          width: 4px;
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
          border-radius: 0 2px 2px 0;
        }
      }

      .notification-icon {
        margin-right: 16px;
        margin-top: 4px;
        padding: 10px;
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;

        .el-icon {
          font-size: 20px;
        }

        &.info {
          background: linear-gradient(135deg, rgba(64, 158, 255, 0.15) 0%, rgba(64, 158, 255, 0.05) 100%);

          .el-icon {
            color: #409eff;
          }
        }

        &.success {
          background: linear-gradient(135deg, rgba(103, 194, 58, 0.15) 0%, rgba(103, 194, 58, 0.05) 100%);

          .el-icon {
            color: #67c23a;
          }
        }

        &.warning {
          background: linear-gradient(135deg, rgba(230, 162, 60, 0.15) 0%, rgba(230, 162, 60, 0.05) 100%);

          .el-icon {
            color: #e6a23c;
          }
        }

        &.error {
          background: linear-gradient(135deg, rgba(245, 108, 108, 0.15) 0%, rgba(245, 108, 108, 0.05) 100%);

          .el-icon {
            color: #f56c6c;
          }
        }
      }

      .notification-content {
        flex: 1;
        min-width: 0;

        .notification-text {
          font-size: 15px;
          color: #303133;
          font-weight: 600;
          margin-bottom: 6px;
          line-height: 1.4;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          line-clamp: 1;
          -webkit-box-orient: vertical;
          overflow: hidden;
        }

        .notification-desc {
          font-size: 13px;
          color: #606266;
          line-height: 1.5;
          margin-bottom: 8px;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
          overflow: hidden;
        }

        .notification-time {
          font-size: 12px;
          color: #909399;
          font-weight: 500;
          padding: 2px 8px;
          background: rgba(144, 147, 153, 0.1);
          border-radius: 6px;
          display: inline-block;
        }
      }

      .notification-status {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 8px;
        padding-top: 4px;

        .el-badge {
          .el-badge__content {
            background: linear-gradient(135deg, #f56c6c 0%, #ff7875 100%);
            border: 2px solid white;
            box-shadow: 0 2px 4px rgba(245, 108, 108, 0.3);
          }
        }

        .remove-btn {
          opacity: 0;
          transition: all 0.3s ease;
          padding: 6px;
          border-radius: 6px;
          background: rgba(245, 108, 108, 0.1);

          .el-icon {
            font-size: 14px;
            color: #f56c6c;
          }

          &:hover {
            background: rgba(245, 108, 108, 0.2);
            transform: scale(1.1);
          }
        }
      }

      &:hover .remove-btn {
        opacity: 1;
      }
    }
  }

  .notification-footer {
    padding: 16px 24px;
    text-align: center;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-top: 1px solid rgba(0, 0, 0, 0.06);

    .el-button {
      font-size: 13px;
      font-weight: 600;
      color: #667eea;
      padding: 8px 20px;
      border-radius: 8px;
      background: white;
      border: 1px solid rgba(102, 126, 234, 0.2);
      transition: all 0.3s ease;

      &:hover {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
      }
    }
  }
}

// 通知按钮增强样式
.notification-dropdown {
  .notification-badge {
    position: relative;

    .el-button {
      border-radius: 12px;
      transition: all 0.3s ease;
      background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
      border: 1px solid rgba(102, 126, 234, 0.2);

      &:hover {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        transform: translateY(-2px);
        box-shadow: 0 4px 16px rgba(102, 126, 234, 0.3);
      }

      .el-icon {
        font-size: 18px;
        transition: all 0.3s ease;
      }
    }

    :deep(.el-badge__content) {
      background: linear-gradient(135deg, #f56c6c 0%, #ff7875 100%);
      border: 2px solid white;
      font-weight: 600;
      font-size: 11px;
      min-width: 18px;
      height: 18px;
      line-height: 14px;
      box-shadow: 0 2px 8px rgba(245, 108, 108, 0.4);
      animation: pulse 2s infinite;
    }
  }
}

// 通知徽章动画
@keyframes pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 2px 8px rgba(245, 108, 108, 0.4);
  }

  50% {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(245, 108, 108, 0.6);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 2px 8px rgba(245, 108, 108, 0.4);
  }
}

// 通知项进入动画
.notification-item {
  animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}
</style>
